#!/usr/bin/ruby

require 'rexml/document'
require 'rexml/streamlistener'
include REXML

file=ARGV[0]

class Escucha
  include StreamListener

  @@tabla = {"micasa" => "myhome", "habitacion" => "room", "mueble" => "furniture", "puerta" => "door"}
  @@contadores = {"micasa" => 0, "habitacion" => 0, "mueble" => 0, "puerta" => 0}

  def tag_start(name, attributes)
    @@contadores[name] = @@contadores[name] + 1
    puts "<#{@@tabla[name]}>"
  end

  def tag_end(name)
    puts "</#{@@tabla[name]}>"
    if (name == "micasa")
      @@contadores.each {|key, value| puts "Se han traducido #{value} etiquetas con nombre #{key}"}
    end
  end

  def text(text)
    puts text
  end

end

listener = Escucha.new
parser = Parsers::StreamParser.new(File.new(file), listener)
parser.parse

